package vendas.dto;

import gminet.infra.dao.TransferObject;
import gminet.infra.toolkit.NumberToolkit;

import java.util.Date;

public class ReportOrder extends TransferObject {

    private static final long serialVersionUID = 9077993440330235280L;

    private User user;
    private Date paymentDate;
    private CurrencyType currencyType;
    private boolean pendent;
    private float currencyValue;
    private float totalBuyValue;
    private float totalShippingValue;
    private float totalTaxValue;
    private float totalSellValue;

    public ReportOrder() {
        super();
    }

    public User getUser() {
        if (this.user == null) {
            this.user = new User();
        }
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public Date getPaymentDate() {
        return paymentDate;
    }

    public void setPaymentDate(Date paymentDate) {
        this.paymentDate = paymentDate;
    }

    public CurrencyType getCurrencyType() {
        return currencyType;
    }

    public void setCurrencyType(CurrencyType currencyType) {
        this.currencyType = currencyType;
    }

    public boolean isPendent() {
        return pendent;
    }

    public void setPendent(boolean pendent) {
        this.pendent = pendent;
    }

    public float getCurrencyValue() {
        return currencyValue;
    }

    public void setCurrencyValue(float currencyValue) {
        this.currencyValue = currencyValue;
    }

    public float getTotalBuyValue() {
        return totalBuyValue;
    }

    public void setTotalBuyValue(float totalBuyValue) {
        this.totalBuyValue = totalBuyValue;
    }

    public float getTotalShippingValue() {
        return totalShippingValue;
    }

    public void setTotalShippingValue(float totalShippingValue) {
        this.totalShippingValue = totalShippingValue;
    }

    public float getTotalTaxValue() {
        return totalTaxValue;
    }

    public void setTotalTaxValue(float totalTaxValue) {
        this.totalTaxValue = totalTaxValue;
    }

    public float getTotalSellValue() {
        return totalSellValue;
    }

    public void setTotalSellValue(float totalSellValue) {
        this.totalSellValue = totalSellValue;
    }
    
    public String getStringTotalSellValue() {

        return NumberToolkit.getStringFromDouble(getTotalSellValue());
    }

    private boolean isDollar() {

        return getCurrencyType() != null && getCurrencyType().equals(CurrencyType.DOLLAR);
    }

    public float getTotalFinalBuyValue() {

        float totalBuyValue = 0;
        if (isDollar() && getCurrencyValue() > 0) {
            totalBuyValue = (getTotalBuyValue() + getTotalShippingValue() + getTotalTaxValue()) * getCurrencyValue();
        } else {
            totalBuyValue = getTotalBuyValue() + getTotalShippingValue() + getTotalTaxValue();
        }
        return totalBuyValue;
    }

    public String getStringTotalFinalBuyValue() {

        return NumberToolkit.getStringFromDouble(getTotalFinalBuyValue());
    }

    public float getTotalGainValue() {

        return getTotalSellValue() - getTotalFinalBuyValue();
    }

    public String getStringTotalGainValue() {

        return NumberToolkit.getStringFromDouble(getTotalGainValue());
    }

    @Override
    public boolean equals(Object simpleObject) {

        boolean equals = false;
        if (simpleObject instanceof ReportOrder) {
            ReportOrder auxReportOrder = (ReportOrder) simpleObject;
            equals &= auxReportOrder.getUser().equals(getUser());
            equals &= auxReportOrder.getPaymentDate().equals(getPaymentDate());
            equals &= auxReportOrder.getCurrencyType().equals(getCurrencyType());
            equals &= (auxReportOrder.isPendent() == isPendent());
        }
        return super.equals(simpleObject);
    }

}
